/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package group6renderer.renderernode;

import group6renderer.Display;
import group6renderer.Visitor;

import java.util.ArrayList;

/**
 *
 * @author jonnie
 */
public abstract class TreeNode
{
    private ArrayList<TreeNode> children = new ArrayList<TreeNode>();
    public TreeNode parent;
    protected String name;
    protected int childNum;
    public abstract void drawNode(Display disp);
    public abstract boolean isLeaf();
    public abstract boolean hasClosing();
    public abstract TreeNode copy();
  
    public boolean isCopy=false;
    public boolean copied=false;
    

    
	public void accept(Visitor theVisitor) {
		theVisitor.visit(this);
	} 
    
    
    public TreeNode getChild(int index)
    {
	return children.get(index);
    }
    
    public void addChild(TreeNode child)throws Exception
    {
	children.add(child);
	child.setChildNum(children.indexOf(child));
    }
        
    public void setParent(TreeNode parent)
    {
	this.parent = parent;
    }
    
    public void setChildNum(int num)
    {
    	childNum=num;
    }
    
    
    public String getName()
    {
	return name;
    }
    
    public TreeNode()
    {
    }
    
    public int getChildrenNum()
    {
    	return children.size();
    }

    public void removeChild(int i)
    {
    	if (i<getChildrenNum())
    	{
    		children.remove(i);
    	}
    }

    public boolean lineChange1()
    {
	if (childNum > 0)
	{
	    TreeNode node = parent.getChild(childNum - 1);
	    if (node instanceof BranchNode || node instanceof BreakNode)
	    {
		return true;
	    }
	}

	return false;
    }

    public boolean lineChange2()
    {
	if (getChildrenNum() != 0)
	{
	    TreeNode node = getChild(getChildrenNum() - 1);
	    if (node instanceof BranchNode || node instanceof BreakNode)
	    {
		return true;
	    }
	}

	return false;
    }

}
